package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/14.<br><br>
 *
 * 反转字符串
 */
public class Topic344 {
    public static void main(String[] args) {
        Topic344 instance = new Topic344();

        char[] array = new char[] {'h','e','l','l','o'};
        instance.reverseString(array);
        System.out.println(array);

        array = new char[] {'H','a','n','n','a','h'};
        instance.reverseString(array);
        System.out.println(array);
    }

    public void reverseString(char[] s) {
        int low = 0;
        int high = s.length - 1;

        while (low < high) {
            char temp = s[low];
            s[low] = s[high];
            s[high] = temp;

            low++;
            high--;
        }
    }
}
